<?
@session_start();

require_once("conn.php");
?>
<script>
	
</script>
<table width="300">
	<tr>
		<th width="50">ID</th>
		<th width="150">Order Date</th>
		<th width="100">Status</th>
	</tr>

	<?
		$sql = "SELECT * FROM pch_order ORDER BY id desc";
		$query = mysql_query($sql);
		$total = mysql_num_rows($query);
		$dis = 20;
		$total_page=ceil($total/$dis);
		$page_cur=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
		$k=($page_cur-1)*$dis;
		$sql .= " limit $k,$dis";
		//echo $sql;
		$query = mysql_query($sql);
		while($row = mysql_fetch_array($query)){
			$sql = "SELECT status FROM pch_orderexport WHERE order_id='".$row["id"]."';";
			$qry = mysql_query($sql);
			$rs = mysql_fetch_assoc($qry);
			if($rs["status"] == "1"){
				$status = "<a href='#' onclick=\"viewOrderExport('".$row["id"]."');\">View</a>";
			}else{
				$status = "<a href=\"#\" onclick=\"newOrderExport('".$row["id"]."');\">Order</a>";
			}
	?>
	
		<tr>
			<td><?=$row["id"]?></td>
			<td><div align="center"><?=$row["order_date"]?></div></td>
			<td><div align="center"><?=$status?></div></td>
		<tr>	
	<?
		}
	?>
</table>
	<?	
		if($page_cur>1)
		{
			echo '&nbsp;<a href="#" onclick="orderExport(\''.($page_cur-1).'\');" style="cursor:pointer;color:green;" >Previous</a>';
		}
		else
		{
		  echo 'Previous&nbsp;';
		}
		for($i=1;$i<$total_page;$i++)
		{
			if($page_cur==$i)
			{
				echo "&nbsp;".$i;
			}
			else
			{
			echo '&nbsp;<a href="#" onclick="orderExport(\''.($i).'\');">'.$i.'</a>';
			}
		}
		if($page_cur<$total_page)
		{
			echo '&nbsp;<a href="#" onclick="orderExport(\''.($page_cur+1).'\');">Next</a>';
		}
		else
		{
		 echo '&nbsp;Next';
		}

	?>

<br>